/**
 * outsider.com.cn Inc.
 * Copyright (c) 2011-2022 All Rights Reserved.
 */
package com.yuanmeng.common.core.enums;

import com.yuanmeng.common.core.exception.ServiceException;

import lombok.Getter;

/**
 * @author outsider
 * @version Id: StatusEnum.java, v 0.1 2022/6/1 17:16 outsider Exp $$
 */
@Getter
public enum OrderMethodEnum {
    DELIVERY("DELIVERY", "外卖订单"),

    RESERVE("RESERVE", "预约订单"),

    REAL_TIME("REAL_TIME", "实时订单"),

    VISIT_SERVER("VISIT_SERVER", "上门服务");

    private String code;

    private String message;

    OrderMethodEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getEnumByCode(String code) {
        for (OrderMethodEnum ENUM : OrderMethodEnum.values()) {
            if (ENUM.code.equals(code)) {
                return ENUM.getCode();
            }
        }
        return "";
    }

    /**
     * 枚举值校验
     * @param orderMethod
     */
    public static void validateCommunityOrderMethodEnum(String orderMethod) {
        int num = 0;
        for (OrderMethodEnum ENUM : OrderMethodEnum.values()) {
            if (ENUM.code.equals(orderMethod)) {
                num++;
            }
        }
        if (num == 0) {
            throw new ServiceException("请求参数非法：orderMethod");
        }
    }

    public static String codeQueryValue(String orderMethod) {
        for(OrderMethodEnum ENUM : OrderMethodEnum.values()) {
            if(ENUM.code.equals(orderMethod)) {
                return ENUM.getMessage();
            }
        }
        return "";
    }

    public static String valueQueryCode(String orderMethodValue) {
        for(OrderMethodEnum ENUM : OrderMethodEnum.values()) {
            if(ENUM.message.equals(orderMethodValue)) {
                return ENUM.getCode();
            }
        }
        return "";
    }
}